﻿using ThunderRoad;
using UnityEngine;

namespace BBYScripts
{
    public class UnSpawner : MonoBehaviour
    {
        // 延迟时间
        public int delayTime = 10;
        private Item item;
        private bool destroyed = false;

        private void Start()
        {
            item = GetComponent<Item>();
            // Debug.LogError("已生成:" + gameObject.name);
            // 设置在5秒后调用DestroySelf方法  
            Invoke(nameof(DestroySelf), delayTime);
        }

        // private void OnCollisionEnter(Collision other)
        // {
        //     Invoke(nameof(DestroySelf), 1);
        // }

        public void DestroySelf()
        {
            if (destroyed || item == null)
            {
                return;
            }

            destroyed = true;
            // 销毁包含此脚本的GameObject  

            item.Despawn();
        }
    }
}